package com.flyan.game.motafx.core.util.animate;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.texture.AnimationChannel;
import javafx.scene.image.Image;
import javafx.util.Duration;

/**
 * 行走人物动画
 *
 * @author flyan
 * @version 1.0
 * @email flyan_by_chenu@sina.com
 * @since 2025/1/31
 */
public class WalkingCharacterAnimate {

    private AnimationChannel up;
    private AnimationChannel down;
    private AnimationChannel left;
    private AnimationChannel right;

    private WalkingCharacterAnimate() {  }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {

        private final WalkingCharacterAnimate animate = new WalkingCharacterAnimate();
        private Image image;
        private int framesPreRow;
        private int frameWidth;
        private int frameHeight;
        private Duration duration;

        public Builder image(String assetName) {
            image = FXGL.image(assetName);
            return this;
        }

        public Builder image(Image image) {
            this.image = image;
            return this;
        }

        public Builder frame(int framesPreRow, int frameWidth, int frameHeight) {
            this.framesPreRow = framesPreRow;
            this.frameWidth = frameWidth;
            this.frameHeight = frameHeight;
            return this;
        }

        public Builder duration(Duration duration) {
            this.duration = duration;
            return this;
        }

        public Builder up(int startFrame, int endFrame) {
            animate.up = new AnimationChannel(image, framesPreRow, frameWidth, frameHeight,
                    duration, startFrame, endFrame);
            return this;
        }

        public Builder down(int startFrame, int endFrame) {
            animate.down = new AnimationChannel(image, framesPreRow, frameWidth, frameHeight,
                    duration, startFrame, endFrame);
            return this;
        }

        public Builder left(int startFrame, int endFrame) {
            animate.left = new AnimationChannel(image, framesPreRow, frameWidth, frameHeight,
                    duration, startFrame, endFrame);
            return this;
        }

        public Builder right(int startFrame, int endFrame) {
            animate.right = new AnimationChannel(image, framesPreRow, frameWidth, frameHeight,
                    duration, startFrame, endFrame);
            return this;
        }

        public WalkingCharacterAnimate build() {
            return animate;
        }

    }

    public AnimationChannel getUp() {
        return up;
    }

    public AnimationChannel getDown() {
        return down;
    }

    public AnimationChannel getLeft() {
        return left;
    }

    public AnimationChannel getRight() {
        return right;
    }

}
